//
//  LLModalAnimation.swift
//  WeiBoShiBing
//
//  Created by Bingo on 15/11/10.
//  Copyright © 2015年 Bingo. All rights reserved.
//

import UIKit

class LLModalAnimation:NSObject,UIViewControllerAnimatedTransitioning{

    
    func  transitionDuration(transitionContext: UIViewControllerContextTransitioning?) -> NSTimeInterval{
    
        return 0.5
    }
    
    func animateTransition(transitionContext: UIViewControllerContextTransitioning) {
        
        let toView = transitionContext.viewForKey(UITransitionContextToViewKey)!
        
        toView.transform = CGAffineTransformMakeScale(1, 0)
        toView.layer.anchorPoint = CGPoint(x: 0.5, y: 0)
        
        transitionContext.containerView()?.addSubview(toView)
        UIView.animateWithDuration(transitionDuration(nil), delay: 0, usingSpringWithDamping: 0.7, initialSpringVelocity: 2, options: UIViewAnimationOptions(rawValue: 0), animations: { () -> Void in
            toView.transform = CGAffineTransformIdentity
            }) { (_) -> Void in
               transitionContext.completeTransition(true)
        }
        
    }
}